//声明: 该文件需要 swiper,jqueryui,common,toast,jquery

require(["config"], function(config) {
	require(["com", "jquery", "sw", "formmin", "form", ], function(com, jq, sw, formmin, form) {
		//生成随机验证码
		jq("#dianji").click(function() {
			var arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
			var str = '';
			for(var i = 0; i < 4; i++)
				str += '' + arr[Math.floor(Math.random() * arr.length)];

			document.getElementById('yzm').innerHTML = str;
		})

		$(function() {
			//表单验证
			$.formValidator.initConfig({
				formid: "form1",
				debug: false,
				submitonce: true,
				onerror: function(msg, obj, errorlist) {
					//$.map(errorlist,function(msg1){alert(msg1)});
					alert(msg);
				}

			});

			$("#t_UserName").formValidator({ onshow: "5-10个字符", onfocus: "5-10个字符", oncorrect: "该用户名可以注册" }).inputValidator({ min: 5, max: 10, onerror: "输入有误" }).regexValidator({ regexp: "username", datatype: "enum", onerror: "格式有误" });
			$("#iptNickName").formValidator({ onshow: "至少4个字符", onfocus: "至少4个字符", oncorrect: "通过" }).inputValidator({ min: 4, empty: { leftempty: false, rightempty: false, emptyerror: "输入有误" }, onerror: "输入有误" });
			$("#t_UserPass").formValidator({ onshow: "至少6个字符", onfocus: "至少6个字符", oncorrect: "密码合法" }).inputValidator({ min: 6, empty: { leftempty: false, rightempty: false, emptyerror: "输入有误" }, onerror: "输入有误" });
			$("#t_RePass").formValidator({ onshow: "请再次输入密码", onfocus: "请再次输入密码", oncorrect: "密码一致" }).inputValidator({ min: 6, empty: { leftempty: false, rightempty: false, emptyerror: "输入有误" }, onerror: "输入有误" }).compareValidator({ desid: "t_UserPass", operateor: "=", onerror: "密码不一致" });
			$("#iptName").formValidator({ onshow: "至少4个字符", onfocus: "至少4个字符", oncorrect: "通过" }).inputValidator({ min: 4, empty: { leftempty: false, rightempty: false, emptyerror: "输入有误" }, onerror: "输入有误" });
			$("#iptCard").formValidator({ onshow: "15或18位的身份证", onfocus: "15或18位的身份证", oncorrect: "输入正确" }).functionValidator({ fun: isCardID });
			$("#t_Email").formValidator({ onshow: "6-100个字符", onfocus: "6-100个字符", oncorrect: "恭喜你,你输对了", defaultvalue: "@" }).inputValidator({ min: 6, max: 100, onerror: "长度非法" }).regexValidator({ regexp: "^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$", onerror: "格式不正确" });

		})

		/*function setCookie(key, val, expires) {
			var now = new Date();
			now.setDate(now.getDate() + expires);
			document.cookie = key + "=" + val + "; expires=" + now;
		}

		function getCookie(key) {
			var cookiestr = document.cookie;
			var list = cookiestr.split("; ");
			for(var attr in list) {
				var kv = list[attr].split("=");
				if(kv[0] == key) {
					return kv[1];
				}
			}
			return "";
		}*/
		//存cookie
		$("#reserve").click(function() {

			//当进行点击的时候判断是否都为正确

			var arr = $(".reg_input");
			var biaoji = true; //默认是正确的
			arr.each(function(index) {
				if($(this).val().length == 0) {
					biaoji = false;
				}

			})

			if(biaoji==false) {
				console.log("cuowu")
				alert("您输入有误。请重新输入");
			} else {
				var usename = $("#t_UserName").val();
				var password = $("#t_UserPass").val();
				com.setCookie(usename, password, 10);
				location.href = "registersucced.html";
			
			}
		})

	});
})